package com.magic.gre.ui.fragment;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.magic.gre.R;
import com.magic.gre.adapter.Guide3Adapter;
import com.magic.gre.base.fragment.BaseFragment;
import com.magic.gre.entity.Guide3Bean;
import com.magic.gre.entity.SerializableMap;
import com.noname.lib_base_java.entity.MsgEvent;
import com.noname.lib_base_java.net.RxBus;
import com.noname.lib_base_java.util.L;
import com.noname.lib_base_java.util.SelectHelper;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author: Lmoumou
 * Date: 2019-01-11 18:20
 * 文件名: Guide6Fragment
 * 描述:
 */
public class Guide6Fragment extends BaseFragment implements Guide3Adapter.OnItemClickListener {
    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;
    @BindView(R.id.next_tv)
    Button nextTv;

    public static Guide6Fragment newInstance(SerializableMap serializableMap) {
        Guide6Fragment fragment = new Guide6Fragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("parmsMap", serializableMap);
        fragment.setArguments(bundle);
        return fragment;
    }

    private SerializableMap serializableMap;

    private Guide3Adapter adapter;
    private List<Guide3Bean> dataList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_guide_6;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        initData();
        serializableMap = (SerializableMap) getArguments().getSerializable("parmsMap");
        adapter = new Guide3Adapter(mContext, dataList);
        adapter.setOnItemClickListener(this);
        mRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 2));
        mRecyclerView.setAdapter(adapter);
    }

    @OnClick(value = {R.id.skip_bt, R.id.next_tv})
    protected void onClick(View view) {
        switch (view.getId()) {
            case R.id.skip_bt:
                RxBus.getInstance().post(new MsgEvent(MsgEvent.GUIDE_SUMBIT));
                break;
            case R.id.next_tv:
                Guide3Bean selectBean = SelectHelper.getSelectBean(dataList);
                if (selectBean != null) {
                    serializableMap.getMap().put("target", selectBean.getContent());
                }
                RxBus.getInstance().post(new MsgEvent(MsgEvent.GUIDE_SUMBIT));
                break;

        }
    }

    private void initData() {
        dataList.clear();
        Guide3Bean bean = new Guide3Bean("315+");
        dataList.add(bean);
        dataList.add(new Guide3Bean("320+"));
        dataList.add(new Guide3Bean("325+"));
        dataList.add(new Guide3Bean("330+"));
        dataList.add(new Guide3Bean("335+"));
    }


    @Override
    public void onItemClick() {
        L.e("KKKKK","onItemClick");
        nextTv.setEnabled(true);
    }
}
